home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / istream.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  40.3 KB  |  1,966 lines

  1. #ifndef __ISTREAM_CC
  2. #define __ISTREAM_CC
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * istream.cc - istream definitions
  8.  *
  9.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  10.  * ALL RIGHTS RESERVED *
  11.  * The software and information contained herein are proprietary to, and
  12.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  13.  * intends to preserve as trade secrets such software and information.
  14.  * This software is furnished pursuant to a written license agreement and
  15.  * may be used, copied, transmitted, and stored only in accordance with
  16.  * the terms of such license and with the inclusion of the above copyright
  17.  * notice.  This software and information or any other copies thereof may
  18.  * not be provided or otherwise made available to any other person.
  19.  *
  20.  * Notwithstanding any other lease or license that may pertain to, or
  21.  * accompany the delivery of, this computer software and information, the
  22.  * rights of the Government regarding its use, reproduction and disclosure
  23.  * are as set forth in Section 52.227-19 of the FARS Computer
  24.  * Software-Restricted Rights clause.
  25.  * 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  28.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  29.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  30.  * P.O. Box 2328, Corvallis, Oregon 97339.
  31.  *
  32.  * This computer software and information is distributed with "restricted
  33.  * rights."  Use, duplication or disclosure is subject to restrictions as
  34.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  35.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  36.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  37.  * then the "Alternate III" clause applies.
  38.  *
  39.  **************************************************************************/
  40.  
  41. #ifndef _RWSTD_NO_NEW_HEADER
  42. #include <cctype>
  43. #else
  44. #include <ctype.h>
  45. #endif
  46.  
  47. #include <ios>
  48.  
  49. #ifndef _RWSTD_NO_NAMESPACE
  50. namespace std {
  51. #endif
  52.  
  53. /*
  54.  * Standard basic_istream manipulators
  55.  *
  56.  * skips the next available white spaces
  57.  */
  58.  
  59. template<class charT, class traits>
  60. basic_istream<charT, traits>&
  61. _RWSTDExport ws(basic_istream<charT, traits>& is)
  62. {
  63.    _TYPENAME traits::int_type        c;
  64.  
  65.    #ifdef _RWSTD_MULTI_THREAD
  66.     #ifndef _RWSTD_NO_EXCEPTIONS
  67.      try {
  68.     #endif
  69.      if ( is.rdbuf() )
  70.      {
  71.        _RWSTDGuard* tmp = new _RWSTDGuard(is.rdbuf()->buffer_mutex_);
  72.        if ( tmp )
  73.               is.istream_sentry_guard = tmp;
  74.              else
  75.               is.istream_sentry_guard = 0;
  76.      }
  77.    #endif
  78.  
  79.  
  80.    #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  81.      const ctype<charT>& ct = use_facet< ctype<charT> >(is.getloc());
  82.    #else
  83.      const ctype<charT>& ct = use_facet(is.getloc(),(ctype<charT>*)0);
  84.    #endif
  85.          
  86.    while((c = is.rdbuf()->sgetc()),
  87.          ( !traits::eq_int_type(c,traits::eof()) && ct.is(ct.space,c) )) 
  88.     is.rdbuf()->snextc();
  89.  
  90.    if( traits::eq_int_type(c,traits::eof()) )
  91.      is.setstate(ios_base::eofbit);
  92.        
  93.   #ifdef _RWSTD_MULTI_THREAD
  94.    if ( is.istream_sentry_guard )
  95.     {
  96.       delete is.istream_sentry_guard;
  97.       is.istream_sentry_guard = 0;
  98.     }
  99.   #endif
  100.  
  101. #ifdef _RWSTD_MULTI_THREAD
  102.  #ifndef _RWSTD_NO_EXCEPTIONS
  103.   }
  104.  
  105.   catch(...)
  106.   {
  107.     if ( is.istream_sentry_guard )
  108.     {
  109.       delete is.istream_sentry_guard;
  110.       is.istream_sentry_guard = 0;
  111.       throw;
  112.     }
  113.   }
  114.  #endif
  115. #endif
  116.  
  117.  
  118.  
  119.   return is;
  120. }
  121.  
  122.  
  123.  
  124. /*
  125.  * basic_istream(basic_streambuf *)
  126.  */
  127.  
  128. template<class charT, class traits>
  129. basic_istream<charT, traits>::
  130. basic_istream(basic_streambuf<charT, traits> *sb)
  131. : chcount_(0)
  132. {
  133.   if ( sb )
  134.    {
  135.      if ( sb->which_open_mode() & ios_base::in )
  136.        init(sb);
  137.      else
  138.        init(0);
  139.    } 
  140.   else
  141.    init(0); 
  142. }
  143.  
  144. /*
  145.  * basic_istream( )
  146.  */
  147.  
  148. template<class charT, class traits>
  149. basic_istream<charT, traits>::
  150. basic_istream( )
  151. : chcount_(0)
  152. }
  153.  
  154.  
  155. /*
  156.  * ~basic_istream();
  157.  */
  158.  
  159. template<class charT, class traits>
  160. basic_istream<charT, traits>::~basic_istream()
  161. {
  162.  
  163. }
  164.  
  165. /*
  166.  * istream_type& operator>>(istream_type& (*pf)(istream_type&))
  167.  *
  168.  * for functions relating to istreams
  169.  */
  170.  
  171. template<class charT, class traits>
  172. basic_istream<charT, traits>&
  173. basic_istream<charT, traits>::
  174. operator>>(basic_istream<charT,traits>& (*pf)(basic_istream<charT,traits>&))
  175. {
  176.   (*pf)(*this);
  177.   return *this;
  178. }
  179.  
  180.  
  181. /*
  182.  * istream_type& operator>>(ios_base& (*pf)(ios_base&))
  183.  *
  184.  * for manipulators relating to the ios_base class
  185.  */
  186.  
  187. template<class charT, class traits>
  188. basic_istream<charT, traits>&
  189. basic_istream<charT, traits>::
  190. operator>>(ios_base& (*pf)(ios_base&))
  191. {
  192.   (*pf)(*this);
  193.  
  194.   return *this;
  195. }
  196.  
  197. /*
  198.  * istream_type& operator>>(ios_type& (*pf)(ios_type&))
  199.  *
  200.  * used to set one of the ios states (ios manipulator)
  201.  */
  202.  
  203. template<class charT, class traits>
  204. basic_istream<charT, traits>&
  205. basic_istream<charT, traits>::
  206. operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&))
  207. {
  208.   (*pf)(*this);
  209.  
  210.   return *this;
  211. }
  212.  
  213. /*
  214.  * basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>, charT *)
  215.  *
  216.  * read in a charT *. 
  217.  */
  218.  
  219. template<class charT, class traits>
  220. basic_istream<charT, traits>&
  221. _RWSTDExport operator>>(basic_istream<charT, traits>& is, charT *p)
  222. {
  223.   ios_base::iostate err = 0;
  224.  
  225.   #ifndef _RWSTD_NO_EXCEPTIONS
  226.   try {
  227.   #endif  
  228.  
  229.  if ( p!=0 )
  230.  {
  231.  
  232.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(is);
  233.  
  234.   if(ipfx) { 
  235.      charT                      *op = p;
  236.      _TYPENAME traits::int_type  c = 0;
  237.      int                        len; 
  238.  
  239.   if ( is.width() == 0 ) len=0; 
  240.   else len=is.width(); 
  241.  
  242.          #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  243.           const ctype<charT>& ct = use_facet< ctype<charT> >(is.getloc());
  244.          #else
  245.           const ctype<charT>& ct = use_facet(is.getloc(), (ctype<charT>*)0);
  246.          #endif
  247.  
  248.      while(--len &&
  249.                (c = is.rdbuf()->sgetc(),!( traits::eq_int_type(c,traits::eof()) ||
  250.                 ct.is(ct.space,c))))
  251.         {
  252.             *p++ = c;
  253.         is.rdbuf()->sbumpc();
  254.      }
  255.     
  256.      if( traits::eq_int_type(c,traits::eof()) )
  257.         err = ((p == op) ? 
  258.                   (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit);
  259.      *p = charT ('\0');  
  260.      is.width(0); 
  261.   }
  262.  
  263. }
  264. else
  265.   err = ios_base::failbit;
  266.  
  267.   #ifndef _RWSTD_NO_EXCEPTIONS
  268.   }
  269.   #endif
  270.  
  271.   #ifndef _RWSTD_NO_EXCEPTIONS
  272.   catch(...)
  273.   {
  274.     bool flag = false;
  275.     try {
  276.            is.setstate(ios_base::badbit);
  277.         }
  278.     catch( ios_base::failure ) { flag= true; }
  279.     if ( flag ) throw;
  280.   }
  281.   #endif
  282.  
  283.   if ( err ) is.setstate(err);
  284.  
  285.   return is;
  286. }
  287.  
  288. /*
  289.  * basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT& )
  290.  *
  291.  * read in a character
  292.  */
  293.  
  294. template<class charT, class traits>
  295. basic_istream<charT, traits>&
  296. _RWSTDExport operator>>(basic_istream<charT,traits>& is, charT& c)
  297. {
  298.  ios_base::iostate err = 0;
  299.  
  300.   #ifndef _RWSTD_NO_EXCEPTIONS
  301.   try {
  302.   #endif  
  303.  
  304.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(is);
  305.  
  306.   if(ipfx) { 
  307.              _TYPENAME traits::int_type tmp = is.rdbuf()->sbumpc();
  308.              if ( traits::eq_int_type(traits::eof(),tmp) ) 
  309.                err = ios_base::failbit | ios_base::eofbit;
  310.              else
  311.                c = traits::to_char_type(tmp);
  312.   }
  313.  
  314.   #ifndef _RWSTD_NO_EXCEPTIONS
  315.   }
  316.   #endif
  317.  
  318.   
  319.   #ifndef _RWSTD_NO_EXCEPTIONS
  320.   catch(...)
  321.   {
  322.     bool flag = false;
  323.     try {
  324.            is.setstate(ios_base::badbit);
  325.         }
  326.     catch( ios_base::failure ) { flag= true; }
  327.     if ( flag ) throw;
  328.   }
  329.   #endif
  330.  
  331.   if ( err ) is.setstate(err);
  332.  
  333.   return is;
  334. }
  335.  
  336.  
  337. #ifndef _RWSTD_NO_SIGNED_CHAR_IN_STREAMS
  338. /*
  339.  * istream& operator>>(basic_istream<char,traits>&,unsigned char& )
  340.  *
  341.  */
  342.  
  343. template <class traits>
  344. basic_istream<char, traits>&
  345. _RWSTDExport operator>>(basic_istream<char, traits>& is, unsigned char& uc)
  346. {
  347.   is >> (char &)uc;
  348.  
  349.   return is;
  350. }
  351.  
  352. /*
  353.  * istream& operator>>(basic_istream<char, traits>&, signed char& )
  354.  *
  355.  */
  356.  
  357. template <class traits>
  358. basic_istream<char, traits>&
  359. _RWSTDExport operator>>(basic_istream<char, traits>& is, signed char& sc)
  360. {
  361.   is >> (char &)sc;
  362.  
  363.   return is;
  364. }
  365.  
  366.  
  367. /*
  368.  * istream& operator>>(basic_istream<char, traits>&, unsigned char* )
  369.  *
  370.  */
  371.  
  372. template <class traits>
  373. basic_istream<char, traits>&
  374. _RWSTDExport operator>>(basic_istream<char, traits>& is,unsigned char* uc)
  375. {
  376.   is >> (char *)uc;
  377.  
  378.   return is;
  379. }
  380.  
  381. /*
  382.  * istream& operator>>(basic_istream<char, traits>&,signed char* )
  383.  *
  384.  */
  385.  
  386. template <class traits>
  387. basic_istream<char, traits>&
  388. _RWSTDExport operator>>(basic_istream<char, traits>& is, signed char* sc)
  389. {
  390.    is >> (char *)sc;
  391.  
  392.    return is;
  393. }
  394.  
  395. #endif
  396.  
  397. #ifndef _RWSTD_NO_BOOL
  398. /*
  399.  * istream_type& operator>>(bool&)
  400.  */
  401.  
  402. template<class charT, class traits>
  403. basic_istream<charT, traits>&
  404. basic_istream<charT, traits>::operator>>(bool& n)
  405. {
  406.  ios_base::iostate err = 0;
  407.  
  408.  #ifndef _RWSTD_NO_EXCEPTIONS
  409.  try {
  410.  #endif
  411.  
  412.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  413.  
  414.   if(ipfx) 
  415.  {
  416.    #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  417.     use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  418.    #else
  419.     use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  420.    #endif
  421.      .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  422.   }
  423.  
  424.   #ifndef _RWSTD_NO_EXCEPTIONS
  425.   }
  426.   #endif
  427.  
  428.   #ifndef _RWSTD_NO_EXCEPTIONS
  429.   catch(...)
  430.   {
  431.     bool flag = false;
  432.     try {
  433.            this->setstate(ios_base::badbit);
  434.         }
  435.     catch( ios_base::failure ) { flag= true; }
  436.     if ( flag ) throw;
  437.   }
  438.   #endif
  439.  
  440.   if ( err ) this->setstate(err);
  441.   
  442.   return *this;
  443. }
  444.  
  445. #endif /* _RWSTD_NO_BOOL */
  446.  
  447. /*
  448.  * istream_type& operator>>(short&)
  449.  */
  450.  
  451. template<class charT, class traits>
  452. basic_istream<charT, traits>&
  453. basic_istream<charT, traits>::operator>>(short& n)
  454. {
  455.  ios_base::iostate err = 0;
  456.  
  457.  #ifndef _RWSTD_NO_EXCEPTIONS
  458.  try {
  459.  #endif 
  460.  
  461.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  462.  
  463.  if(ipfx) 
  464.  {
  465.   long l;
  466.   #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  467.    use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  468.   #else
  469.    use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  470.   #endif
  471.   .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,l);
  472.   n=(short)l;
  473.   if ( (n!=l) && ((unsigned short)n != l) )
  474.    err |= ios_base::failbit;
  475.  }
  476.  
  477. #ifndef _RWSTD_NO_EXCEPTIONS
  478.   }
  479.   #endif
  480.  
  481.   #ifndef _RWSTD_NO_EXCEPTIONS
  482.   catch(...)
  483.   {
  484.     bool flag = false;
  485.     try {
  486.            this->setstate(ios_base::badbit);
  487.         }
  488.     catch( ios_base::failure ) { flag= true; }
  489.     if ( flag ) throw;
  490.   }
  491.   #endif
  492.  
  493.   if ( err ) this->setstate(err);
  494.  
  495.   return *this;
  496.  
  497.  }
  498.  
  499. /*
  500.  * istream_type& operator>>(unsigned short&)
  501.  */
  502. template<class charT, class traits>
  503. basic_istream<charT, traits>&
  504. basic_istream<charT, traits>::operator>>(unsigned short& n)
  505. {
  506.   ios_base::iostate err = 0;
  507.  
  508.   #ifndef _RWSTD_NO_EXCEPTIONS
  509.   try {
  510.   #endif
  511.  
  512.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  513.  
  514.  
  515.   if(ipfx) {
  516.             #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  517.              use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  518.             #else
  519.              use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  520.             #endif
  521.              .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  522.           }
  523.  
  524.   #ifndef _RWSTD_NO_EXCEPTIONS
  525.   }
  526.   #endif
  527.  
  528.   #ifndef _RWSTD_NO_EXCEPTIONS
  529.   catch(...)
  530.   {
  531.     bool flag = false;
  532.     try {
  533.            this->setstate(ios_base::badbit);
  534.         }
  535.     catch( ios_base::failure ) { flag= true; }
  536.     if ( flag ) throw;
  537.   }
  538.   #endif
  539.  
  540.   if ( err ) this->setstate(err);
  541.  
  542.   return *this;
  543.  
  544. }
  545.  
  546.  
  547. /*
  548.  * istream_type& operator>>(int&)
  549.  */
  550.  
  551. template<class charT, class traits>
  552. basic_istream<charT, traits>&
  553. basic_istream<charT, traits>::operator>>(int& n)
  554. {
  555.  ios_base::iostate err = 0;
  556.  
  557.  #ifndef _RWSTD_NO_EXCEPTIONS
  558.  try {
  559.  #endif
  560.  
  561.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  562.  
  563.  if(ipfx) {
  564.  
  565.           long l;
  566.           #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  567.            use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  568.           #else
  569.            use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  570.           #endif
  571.            .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,l);
  572.            n=(int)l;
  573.            if ( (n!=l) && ((unsigned int)n!=(unsigned long)l) )
  574.            err |= ios_base::failbit;
  575.          }
  576.  
  577.   #ifndef _RWSTD_NO_EXCEPTIONS
  578.   }
  579.   #endif
  580.  
  581.   #ifndef _RWSTD_NO_EXCEPTIONS
  582.   catch(...)
  583.   {
  584.     bool flag = false;
  585.     try {
  586.            this->setstate(ios_base::badbit);
  587.         }
  588.     catch( ios_base::failure ) { flag= true; }
  589.     if ( flag ) throw;
  590.   }
  591.   #endif
  592.  
  593.   if ( err ) this->setstate(err);
  594.  
  595.   return *this;
  596. }
  597.  
  598. /*
  599.  * istream_type& operator>>(unsigned int&)
  600.  */
  601.  
  602. template<class charT, class traits>
  603. basic_istream<charT, traits>&
  604. basic_istream<charT, traits>::operator>>(unsigned int& n)
  605. {
  606.  ios_base::iostate err = 0;
  607.  
  608.  #ifndef _RWSTD_NO_EXCEPTIONS
  609.  try {
  610.  #endif
  611.  
  612.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  613.  
  614.  if(ipfx) {
  615.             #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  616.              use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  617.             #else
  618.              use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  619.             #endif
  620.             .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  621.           }
  622.  
  623.   #ifndef _RWSTD_NO_EXCEPTIONS
  624.   }
  625.   #endif
  626.  
  627.   #ifndef _RWSTD_NO_EXCEPTIONS
  628.   catch(...)
  629.   {
  630.     bool flag = false;
  631.     try {
  632.            this->setstate(ios_base::badbit);
  633.         }
  634.     catch( ios_base::failure ) { flag= true; }
  635.     if ( flag ) throw;
  636.   }
  637.   #endif
  638.  
  639.   if ( err ) this->setstate(err); 
  640.  
  641.   return *this;
  642.  
  643. }
  644.  
  645. /*
  646.  * istream_type& operator>>(long&)
  647.  */
  648.  
  649. template<class charT, class traits>
  650. basic_istream<charT, traits>&
  651. basic_istream<charT, traits>::operator>>(long& n)
  652. {
  653.  ios_base::iostate err = 0;
  654.  
  655.  #ifndef _RWSTD_NO_EXCEPTIONS
  656.  try {
  657.  #endif
  658.  
  659.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  660.  
  661.  if(ipfx) {
  662.  
  663.            #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  664.             use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  665.            #else
  666.             use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  667.            #endif
  668.            .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  669.           }
  670.  
  671.   #ifndef _RWSTD_NO_EXCEPTIONS
  672.   }
  673.   #endif
  674.  
  675.   #ifndef _RWSTD_NO_EXCEPTIONS
  676.   catch(...)
  677.   {
  678.     bool flag = false;
  679.     try {
  680.            this->setstate(ios_base::badbit);
  681.         }
  682.     catch( ios_base::failure ) { flag= true; }
  683.     if ( flag ) throw;
  684.   }
  685.   #endif
  686.  
  687.   if ( err ) this->setstate(err);
  688.  
  689.   return *this;
  690.  
  691.   
  692. }
  693.  
  694. /*
  695.  * istream_type& operator>>(unsigned long&)
  696.  */
  697.  
  698. template<class charT, class traits>
  699. basic_istream<charT, traits>&
  700. basic_istream<charT, traits>::operator>>(unsigned long& n)
  701. {
  702.  ios_base::iostate err = 0;
  703.  
  704.  #ifndef _RWSTD_NO_EXCEPTIONS
  705.  try {
  706.  #endif
  707.  
  708. _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  709.  
  710.  if(ipfx) {
  711.             #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  712.              use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  713.             #else
  714.              use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  715.             #endif
  716.             .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  717.            }
  718.  
  719.   #ifndef _RWSTD_NO_EXCEPTIONS
  720.   }
  721.   #endif
  722.  
  723.   #ifndef _RWSTD_NO_EXCEPTIONS
  724.   catch(...)
  725.   {
  726.     bool flag = false;
  727.     try {
  728.            this->setstate(ios_base::badbit);
  729.         }
  730.     catch( ios_base::failure ) { flag= true; }
  731.     if ( flag ) throw;
  732.   }
  733.   #endif
  734.  
  735.   if ( err ) this->setstate(err);
  736.  
  737.   return *this;
  738. }
  739.  
  740. /*
  741.  * istream_type& operator>>(float&)
  742.  */
  743.  
  744. template<class charT, class traits>
  745. basic_istream<charT, traits>&
  746. basic_istream<charT, traits>::operator>>(float& f)
  747. {
  748.  ios_base::iostate err = 0;
  749.  
  750.  #ifndef _RWSTD_NO_EXCEPTIONS
  751.  try {
  752.  #endif
  753.  
  754.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  755.  
  756.  if(ipfx) { 
  757.             #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  758.              use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  759.             #else
  760.              use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  761.             #endif
  762.             .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,f);
  763.           }
  764.  
  765.   #ifndef _RWSTD_NO_EXCEPTIONS
  766.   }
  767.   #endif
  768.  
  769.   #ifndef _RWSTD_NO_EXCEPTIONS
  770.   catch(...)
  771.   {
  772.     bool flag = false;
  773.     try {
  774.            this->setstate(ios_base::badbit);
  775.         }
  776.     catch( ios_base::failure ) { flag= true; }
  777.     if ( flag ) throw;
  778.   }
  779.   #endif
  780.  
  781.   if ( err ) this->setstate(err);
  782.  
  783.   return *this;
  784.  
  785. }
  786.  
  787. /*
  788.  * istream_type& operator>>(double&)
  789.  */
  790.  
  791. template<class charT, class traits>
  792. basic_istream<charT, traits>&
  793. basic_istream<charT, traits>::operator>>(double& f)
  794. {
  795.  ios_base::iostate err = 0;
  796.  
  797.  #ifndef _RWSTD_NO_EXCEPTIONS
  798.  try {
  799.  #endif  
  800.  
  801. _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  802.  
  803. if(ipfx) {
  804.            #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  805.             use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  806.            #else
  807.             use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  808.            #endif
  809.             .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,f);
  810.          }
  811.  
  812.   #ifndef _RWSTD_NO_EXCEPTIONS
  813.   }
  814.   #endif
  815.  
  816.   #ifndef _RWSTD_NO_EXCEPTIONS
  817.   catch(...)
  818.   {
  819.     bool flag = false;
  820.     try {
  821.            this->setstate(ios_base::badbit);
  822.         }
  823.     catch( ios_base::failure ) { flag= true; }
  824.     if ( flag ) throw;
  825.   }
  826.   #endif
  827.  
  828.   if ( err ) this->setstate(err);
  829.  
  830.   return *this;
  831.  
  832. }
  833.  
  834. /*
  835.  * istream_type& operator>>(long double&)
  836.  */
  837.  
  838. template<class charT, class traits>
  839. basic_istream<charT, traits>&
  840. basic_istream<charT, traits>::operator>>(long double& f)
  841. {
  842.  ios_base::iostate err = 0;
  843.  
  844.  #ifndef _RWSTD_NO_EXCEPTIONS
  845.  try {
  846.  #endif  
  847.  
  848.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  849.  
  850.  if(ipfx) {  
  851.              #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  852.               use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  853.              #else   
  854.              use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  855.              #endif
  856.               .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,f);
  857.            }
  858.  
  859.   #ifndef _RWSTD_NO_EXCEPTIONS
  860.   }
  861.   #endif
  862.  
  863.   #ifndef _RWSTD_NO_EXCEPTIONS
  864.   catch(...)
  865.   {
  866.     bool flag = false;
  867.     try {
  868.            this->setstate(ios_base::badbit);
  869.         }
  870.     catch( ios_base::failure ) { flag= true; }
  871.     if ( flag ) throw;
  872.   }
  873.   #endif
  874.  
  875.   if ( err ) this->setstate(err);
  876.  
  877.   return *this;
  878. }
  879.  
  880. /*
  881.  * istream_type& operator>>(_RWSTD_LONG_LONG&)
  882.  */
  883.  
  884. #ifdef _RWSTD_LONG_LONG
  885.  
  886. template<class charT, class traits>
  887. basic_istream<charT, traits>&
  888. basic_istream<charT, traits>::operator>>(_RWSTD_LONG_LONG& ll)
  889. {
  890.  ios_base::iostate err = 0;
  891.  
  892.  #ifndef _RWSTD_NO_EXCEPTIONS
  893.  try {
  894.  #endif 
  895.  
  896.  _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  897.  
  898.  if(ipfx) { 
  899.              #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  900.               use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  901.              #else  
  902.              use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  903.              #endif
  904.               .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,ll);
  905.            }
  906.  
  907.   #ifndef _RWSTD_NO_EXCEPTIONS
  908.   }
  909.   #endif
  910.  
  911.   #ifndef _RWSTD_NO_EXCEPTIONS
  912.   catch(...)
  913.   {
  914.     bool flag = false;
  915.     try {
  916.            this->setstate(ios_base::badbit);
  917.         }
  918.     catch( ios_base::failure ) { flag= true; }
  919.     if ( flag ) throw;
  920.   }
  921.   #endif
  922.  
  923.   if ( err ) this->setstate(err);
  924.  
  925.   return *this;
  926. }
  927. #endif // _RWSTD_LONG_LONG
  928.  
  929. /*
  930.  * istream_type& operator>>(void*&)
  931.  */
  932.  
  933. template<class charT, class traits>
  934. basic_istream<charT, traits>&
  935. basic_istream<charT, traits>::operator>>(void*& p)
  936. {
  937.   ios_base::iostate err = 0;
  938.  
  939.  #ifndef _RWSTD_NO_EXCEPTIONS
  940.  try {
  941.  #endif
  942.  
  943.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  944.  
  945.   if(ipfx) 
  946.  {
  947.    #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  948.     use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  949.    #else
  950.     use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  951.    #endif
  952.      .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,p);
  953.   }
  954.  
  955.   #ifndef _RWSTD_NO_EXCEPTIONS
  956.   }
  957.   #endif
  958.  
  959.   #ifndef _RWSTD_NO_EXCEPTIONS
  960.   catch(...)
  961.   {
  962.     bool flag = false;
  963.     try {
  964.            this->setstate(ios_base::badbit);
  965.         }
  966.     catch( ios_base::failure ) { flag= true; }
  967.     if ( flag ) throw;
  968.   }
  969.   #endif
  970.  
  971.   if ( err ) this->setstate(err);
  972.   
  973.   return *this;
  974. }
  975.  
  976. /*
  977.  * istream_type& operator>>(basic_streambuf&)
  978.  *
  979.  * reads characters from the stream and inserts them into 'sb'
  980.  */
  981.  
  982. template<class charT, class traits>
  983. basic_istream<charT, traits>&
  984. basic_istream<charT, traits>::operator>>(streambuf_type& sb)
  985. {
  986.   ios_base::iostate err = 0;
  987.  
  988.   #ifndef _RWSTD_NO_EXCEPTIONS
  989.   try {
  990.   #endif  
  991.  
  992.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  993.  
  994.   if(ipfx) {
  995.     int_type         c;
  996.  
  997.     if ( traits::eq_int_type(rdbuf()->sgetc(),traits::eof()) ) 
  998.      err = ios_base::failbit; 
  999.          
  1000.     while( !traits::eq_int_type( (c = rdbuf()->sgetc()),traits::eof()) ) {
  1001.         if( traits::eq_int_type(sb.sputc(c),traits::eof()) ) { 
  1002.         err = ios_base::failbit;
  1003.         break;
  1004.       }
  1005.       rdbuf()->sbumpc();  
  1006.     }
  1007.  
  1008.     if( traits::eq_int_type(c,traits::eof()) ) 
  1009.       err |= ios_base::eofbit;  
  1010.   }
  1011.  
  1012.   #ifndef _RWSTD_NO_EXCEPTIONS
  1013.   }
  1014.   #endif
  1015.  
  1016.   #ifndef _RWSTD_NO_EXCEPTIONS
  1017.   catch(...)
  1018.   {
  1019.     bool flag = false;
  1020.     try {
  1021.             this->setstate(ios_base::failbit);
  1022.         }
  1023.     catch( ios_base::failure ) { flag= true; }
  1024.     if ( flag ) throw;
  1025.   }
  1026.   #endif
  1027.  
  1028.   if ( err ) this->setstate(err);
  1029.  
  1030.   return *this;
  1031. }
  1032.  
  1033. /*
  1034.  * istream_type& operator>>(basic_streambuf *)
  1035.  *
  1036.  * reads characters from the stream and inserts them into 'sb'
  1037.  */
  1038.  
  1039. template<class charT, class traits>
  1040. basic_istream<charT, traits>&
  1041. basic_istream<charT, traits>::operator>>(streambuf_type *sb)
  1042. {
  1043.   ios_base::iostate err = 0;
  1044.  
  1045.   #ifndef _RWSTD_NO_EXCEPTIONS
  1046.   try {
  1047.   #endif 
  1048.  
  1049.  if ( sb!=0 )
  1050.  {
  1051.   
  1052.  
  1053.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  1054.  
  1055.   if(ipfx) {
  1056.     int_type         c;
  1057.     
  1058.     if ( traits::eq_int_type(rdbuf()->sgetc(),traits::eof()) ) 
  1059.      err = ios_base::failbit; 
  1060.      
  1061.     while( !traits::eq_int_type( (c = rdbuf()->sgetc()),traits::eof()) ) {
  1062.       if( traits::eq_int_type(sb->sputc(c),traits::eof()) ) { 
  1063.         err = ios_base::failbit;
  1064.         break;
  1065.       }
  1066.       rdbuf()->sbumpc(); 
  1067.     }
  1068.  
  1069.        
  1070.     if( traits::eq_int_type(c,traits::eof()) )
  1071.       err |= ios_base::eofbit;
  1072.    }
  1073.  }
  1074. else
  1075.   err = ios_base::failbit;
  1076.  
  1077.   #ifndef _RWSTD_NO_EXCEPTIONS
  1078.   }
  1079.   #endif
  1080.  
  1081.   #ifndef _RWSTD_NO_EXCEPTIONS
  1082.   catch(...)
  1083.   {
  1084.     bool flag = false;
  1085.     try {
  1086.             this->setstate(ios_base::failbit);
  1087.         }
  1088.     catch( ios_base::failure ) { flag= true; }
  1089.     if ( flag ) throw;
  1090.   }
  1091.   #endif
  1092.  
  1093.   if ( err ) this->setstate(err);
  1094.  
  1095.   return *this;
  1096. }
  1097.  
  1098. /*
  1099.  * istream_type& get(char_type *, streamsize, char_type)
  1100.  *
  1101.  */
  1102.  
  1103. template<class charT, class traits>
  1104. basic_istream<charT, traits>&
  1105. basic_istream<charT, traits>::
  1106. get(char_type *s, streamsize n, char_type delim)
  1107. {
  1108.  ios_base::iostate err = 0; 
  1109.  
  1110.  #ifndef _RWSTD_NO_EXCEPTIONS
  1111.  try {
  1112.  #endif  
  1113.  
  1114.  chcount_ = 0; 
  1115.  
  1116.  if (s!=0)
  1117.  {
  1118.  
  1119.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1120.  
  1121.   if(ipfx) { 
  1122.     char_type  *op = s;
  1123.     int_type   c = 0;
  1124.  
  1125.     while(--n > 0 && (c = rdbuf()->sgetc()) != delim && 
  1126.      ( !traits::eq_int_type(c,traits::eof()) )) {
  1127.       *s++ = c; 
  1128.       ++chcount_;
  1129.       rdbuf()->snextc(); 
  1130.     }
  1131.  
  1132.     if( traits::eq_int_type(c,traits::eof()) )  
  1133.       err = ((s == op) ? (ios_base::eofbit | ios_base::failbit) :
  1134.                            ios_base::eofbit);
  1135.   }
  1136.  
  1137.   *s = 0;   //terminate with null
  1138.  }
  1139. else
  1140.   err = ios_base::badbit;
  1141.  
  1142.   #ifndef _RWSTD_NO_EXCEPTIONS
  1143.   }
  1144.   #endif
  1145.  
  1146.   #ifndef _RWSTD_NO_EXCEPTIONS
  1147.   catch(...)
  1148.   {
  1149.     bool flag = false;
  1150.     try {
  1151.             this->setstate(ios_base::badbit);
  1152.         }
  1153.     catch( ios_base::failure ) { flag= true; }
  1154.     if ( flag ) throw;
  1155.   }
  1156.   #endif
  1157.  
  1158.   if ( err ) this->setstate(err);
  1159.  
  1160.   return *this;
  1161. }
  1162.  
  1163. /*
  1164.  * istream_type& get(char_type&)
  1165.  *
  1166.  * gets a single character, first skipping white space.
  1167.  * see also: int_type get();
  1168.  */
  1169.  
  1170. template<class charT, class traits>
  1171. basic_istream<charT, traits>&
  1172. basic_istream<charT, traits>::get(char_type& s)
  1173. {
  1174.  ios_base::iostate err = 0;  
  1175.  
  1176.  #ifndef _RWSTD_NO_EXCEPTIONS
  1177.  try {
  1178.  #endif
  1179.  
  1180.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1181.  
  1182.   chcount_ = 0;
  1183.  
  1184.   if(ipfx) { 
  1185.              int_type tmp = rdbuf()->sbumpc();
  1186.              if ( traits::eq_int_type(tmp,traits::eof()) ) 
  1187.               {
  1188.                 err = ios_base::failbit | ios_base::eofbit;
  1189.               }
  1190.              else
  1191.               {
  1192.                 s = traits::to_char_type(tmp);
  1193.                 chcount_ = 1;
  1194.               }
  1195.   }
  1196.  
  1197.   #ifndef _RWSTD_NO_EXCEPTIONS
  1198.   }
  1199.   #endif
  1200.  
  1201.   #ifndef _RWSTD_NO_EXCEPTIONS
  1202.   catch(...)
  1203.   {
  1204.     bool flag = false;
  1205.     try {
  1206.             this->setstate(ios_base::badbit);
  1207.         }
  1208.     catch( ios_base::failure ) { flag= true; }
  1209.     if ( flag ) throw;
  1210.   }
  1211.   #endif
  1212.  
  1213.   if ( err ) this->setstate(err);
  1214.  
  1215.   return *this;
  1216. }
  1217.  
  1218. /*
  1219.  * istream_type& get(basic_streambuf&, char_type)
  1220.  *
  1221.  * insert characters into sb upto delim
  1222.  */
  1223.  
  1224. template<class charT, class traits>
  1225. basic_istream<charT, traits>&
  1226. basic_istream<charT, traits>::
  1227. get(streambuf_type& sb, char_type delim)
  1228. {
  1229.  ios_base::iostate err = 0;   
  1230.  
  1231.  #ifndef _RWSTD_NO_EXCEPTIONS
  1232.  try {
  1233.  #endif
  1234.  
  1235.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1236.  
  1237.   chcount_ = 0;
  1238.  
  1239.   if(ipfx) { 
  1240.     int_type        c;
  1241.  
  1242.     while(((c = rdbuf()->sgetc()) != delim) && 
  1243.      ( !traits::eq_int_type(c,traits::eof()) )) {
  1244.       if( traits::eq_int_type(sb.sputc(c),traits::eof()) ) {  
  1245.         err = ios_base::failbit;  
  1246.         break;
  1247.       }
  1248.       ++chcount_;
  1249.       rdbuf()->sbumpc();  
  1250.     }
  1251.  
  1252.     if(c == traits::eof())  
  1253.       err |= ios_base::eofbit;
  1254.   }
  1255.  
  1256.   #ifndef _RWSTD_NO_EXCEPTIONS
  1257.   }
  1258.   #endif
  1259.  
  1260.   #ifndef _RWSTD_NO_EXCEPTIONS
  1261.   catch(...)
  1262.   {
  1263.     bool flag = false;
  1264.     try {
  1265.             this->setstate(ios_base::badbit);
  1266.         }
  1267.     catch( ios_base::failure ) { flag= true; }
  1268.     if ( flag ) throw;
  1269.   }
  1270.   #endif
  1271.  
  1272.   if ( err ) this->setstate(err);
  1273.  
  1274.   return *this;
  1275. }
  1276.  
  1277. /*
  1278.  * istream_type& getline(char_type *, streamsize, char_type)
  1279.  */
  1280.  
  1281. template<class charT, class traits>
  1282. basic_istream<charT, traits>&
  1283. basic_istream<charT, traits>::
  1284. getline(char_type *s, streamsize n, char_type delim)
  1285. {
  1286.  ios_base::iostate err = 0;
  1287.  
  1288.  #ifndef _RWSTD_NO_EXCEPTIONS
  1289.  try {
  1290.  #endif
  1291.  
  1292.  chcount_ = 0; 
  1293.  
  1294.  if (s!=0)
  1295.  {
  1296.  
  1297.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1298.  
  1299.   if(ipfx) {  
  1300.     char_type    *op = s;
  1301.     int_type     c = 0;
  1302.  
  1303.  while( --n > 0 && !traits::eq_int_type( (c = rdbuf()->sgetc()),traits::eof()) ) {
  1304.       ++chcount_;
  1305.       rdbuf()->sbumpc();  
  1306.  
  1307.       if(c == delim)
  1308.          break;
  1309.  
  1310.       *s++ = c;          
  1311.     }
  1312.     *s = 0; 
  1313.     if( traits::eq_int_type(c,traits::eof()) )  
  1314.   err = (s == op) ? (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit;
  1315.  
  1316.     if ( n == 0 ) 
  1317.      {
  1318.        if ( rdbuf()->sgetc() != delim )
  1319.         err |= ios_base::failbit;
  1320.        else
  1321.         rdbuf()->snextc();
  1322.      }
  1323.  
  1324.   }
  1325.   
  1326.   *s = 0;  //terminate with null
  1327.  }
  1328. else
  1329.  err = ios_base::badbit;
  1330.  
  1331.   #ifndef _RWSTD_NO_EXCEPTIONS
  1332.   }
  1333.   #endif
  1334.  
  1335.   #ifndef _RWSTD_NO_EXCEPTIONS
  1336.   catch(...)
  1337.   {
  1338.     bool flag = false;
  1339.     try {
  1340.              this->setstate(ios_base::badbit);
  1341.         }
  1342.     catch( ios_base::failure ) { flag= true; }
  1343.     if ( flag ) throw;
  1344.   }
  1345.   #endif
  1346.  
  1347.   if ( err ) this->setstate(err);
  1348.  
  1349.   return *this;
  1350. }
  1351.  
  1352. /*
  1353.  * istream_type& ignore(streamsize, int_type)
  1354.  *
  1355.  * this ignores characters n characters or until delim
  1356.  */
  1357.  
  1358. template<class charT, class traits>
  1359. basic_istream<charT, traits>&
  1360. basic_istream<charT, traits>::ignore(streamsize n, int_type delim)
  1361. {
  1362.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1363.   
  1364.   chcount_ = 0;
  1365.  
  1366.   if(ipfx) {  
  1367.     int_type      c = 0;
  1368.  
  1369.  while(--n >= 0 && !traits::eq_int_type( (c = rdbuf()->sgetc()),traits::eof()) ) {
  1370.       ++chcount_;
  1371.       rdbuf()->sbumpc();
  1372.       if(c == delim)   
  1373.         break;
  1374.     }
  1375.     if( traits::eq_int_type(c,traits::eof()) )
  1376.       this->setstate(ios_base::eofbit);
  1377.   }
  1378.  
  1379.   return *this;
  1380. }
  1381.  
  1382. /*
  1383.  * istream_type& read(char_type *, streamsize)
  1384.  */
  1385.  
  1386. template<class charT, class traits>
  1387. basic_istream<charT, traits>&
  1388. basic_istream<charT, traits>::read(char_type *s, streamsize n)
  1389. {
  1390.  ios_base::iostate err = 0; 
  1391.  
  1392.  #ifndef _RWSTD_NO_EXCEPTIONS
  1393.  try {
  1394.  #endif 
  1395.  
  1396.  chcount_ = 0;
  1397.  
  1398.  if (s!=0)
  1399.  { 
  1400.  
  1401.   _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1402.  
  1403.   if(ipfx) {  
  1404.     int_type       c = 0;
  1405.  
  1406. while((--n >= 0) && !traits::eq_int_type( (c = rdbuf()->sgetc()),traits::eof()))
  1407.    {
  1408.       *s++ = c; 
  1409.       ++chcount_;
  1410.       rdbuf()->sbumpc();  
  1411.     }
  1412.  
  1413.     if( traits::eq_int_type(c,traits::eof()) )  
  1414.     err = (n >= 0) ? (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit;
  1415.   }
  1416.  
  1417.  }
  1418.  else
  1419.   err = ios_base::badbit;  
  1420.  
  1421.   #ifndef _RWSTD_NO_EXCEPTIONS
  1422.   }
  1423.   #endif
  1424.  
  1425.   #ifndef _RWSTD_NO_EXCEPTIONS
  1426.   catch(...)
  1427.   {
  1428.     bool flag = false;
  1429.     try {
  1430.              this->setstate(ios_base::badbit);
  1431.         }
  1432.     catch( ios_base::failure ) { flag= true; }
  1433.     if ( flag ) throw;
  1434.   }
  1435.   #endif
  1436.  
  1437.   if ( err ) this->setstate(err);
  1438.  
  1439.   return *this;
  1440. }
  1441.  
  1442. /*
  1443.  * streamsize readsome(char_type *, streamsize)
  1444.  */
  1445.  
  1446. template<class charT, class traits>
  1447. streamsize 
  1448. basic_istream<charT, traits>::readsome(char_type *s, streamsize n)
  1449. {
  1450.   int navail = rdbuf()->in_avail();
  1451.  
  1452.    
  1453.   if(navail == -1) {   
  1454.     this->setstate(ios_base::eofbit);
  1455.     return 0;
  1456.   }
  1457.   if(navail == 0 ) return 0;
  1458.  
  1459.  if ( this->good() )
  1460.  {
  1461.   if(n < navail) 
  1462.     { 
  1463.       read(s, n);
  1464.       return (n);
  1465.     }
  1466.  
  1467.   read(s, navail);
  1468.   return (streamsize)(navail);
  1469.  }
  1470.  else
  1471.   { 
  1472.     if ( !(this->rdstate() & ios_base::failbit) )
  1473.      this->setstate(ios_base::failbit);
  1474.   }
  1475.   
  1476.   return 0;
  1477. }
  1478.  
  1479. /*
  1480.  * int peek()
  1481.  */
  1482.  
  1483. template<class charT, class traits>
  1484. int basic_istream<charT, traits>::peek()
  1485. {
  1486.   chcount_ = 0;
  1487.  
  1488.   if(this->good())
  1489.    {
  1490.      #ifdef _RWSTD_MULTI_THREAD
  1491.       if ( rdbuf() )
  1492.        _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1493.      #endif
  1494.  
  1495.      _TYPENAME traits::int_type tmp = rdbuf()->sgetc();
  1496.      if ( !traits::eq_int_type( tmp,traits::eof() ) )
  1497.       chcount_ = 1;
  1498.      return tmp;
  1499.    }
  1500.  
  1501.   return traits::eof();
  1502. }
  1503.  
  1504. /*
  1505.  * pos_type tellg()
  1506.  */
  1507.  
  1508. template<class charT, class traits>
  1509. _TYPENAME basic_istream<charT, traits>::pos_type
  1510. basic_istream<charT, traits>::tellg()
  1511. {
  1512.  ios_base::iostate err = 0; 
  1513.  pos_type         p;
  1514.  
  1515.   #ifndef _RWSTD_NO_EXCEPTIONS
  1516.  try {
  1517.  #endif 
  1518.  
  1519.   #ifdef _RWSTD_MULTI_THREAD
  1520.    if ( rdbuf() )
  1521.     _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1522.   #endif
  1523.  
  1524.   if ( this->bad() ) return pos_type(off_type(-1));   
  1525.  
  1526.   if((p = rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in))
  1527.    == pos_type(off_type(-1)))
  1528.     err = ios_base::failbit;
  1529.  
  1530.   #ifndef _RWSTD_NO_EXCEPTIONS
  1531.   }
  1532.   #endif
  1533.  
  1534.   #ifndef _RWSTD_NO_EXCEPTIONS
  1535.   catch(...)
  1536.   {
  1537.     bool flag = false;
  1538.     try {
  1539.           this->setstate(ios_base::badbit);
  1540.         }
  1541.     catch( ios_base::failure ) { flag= true; }
  1542.     if ( flag ) throw;
  1543.   }
  1544.   #endif
  1545.  
  1546.   if ( err ) this->setstate(err);
  1547.  
  1548.   return p;
  1549. }
  1550.  
  1551. /*
  1552.  * basic_istream& seekg(off_type, ios_base::seekdir)
  1553.  */
  1554.  
  1555. #ifndef _RWSTD_NO_INT_TYPEDEF
  1556. template<class charT, class traits>
  1557. basic_istream<charT, traits>&
  1558. basic_istream<charT, traits>::
  1559. seekg(off_type off, ios_base::seekdir dir)
  1560. {
  1561.  ios_base::iostate err = 0;
  1562.  
  1563.  #ifndef _RWSTD_NO_EXCEPTIONS
  1564.  try {
  1565.  #endif 
  1566.  
  1567.    #ifdef _RWSTD_MULTI_THREAD
  1568.     if ( rdbuf() )
  1569.      _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1570.    #endif 
  1571.  
  1572. if ( !this->bad() )
  1573.  {
  1574.   if (rdbuf())
  1575.   {
  1576.    if( rdbuf()->pubseekoff(off, dir, ios_base::in) == pos_type(off_type(-1)) )
  1577.     err = ios_base::failbit;
  1578.   }
  1579.   else
  1580.    err = ios_base::badbit;
  1581.  }
  1582.  
  1583.   #ifndef _RWSTD_NO_EXCEPTIONS
  1584.   }
  1585.   #endif
  1586.  
  1587.   #ifndef _RWSTD_NO_EXCEPTIONS
  1588.   catch(...)
  1589.   {
  1590.     bool flag = false;
  1591.     try {
  1592.           this->setstate(ios_base::badbit);
  1593.         }
  1594.     catch( ios_base::failure ) { flag= true; }
  1595.     if ( flag ) throw;
  1596.   }
  1597.   #endif
  1598.  
  1599.  if ( err ) this->setstate(err);
  1600.   else
  1601.    if ( !this->bad() )
  1602.     clear(this->rdstate() & ~(ios_base::eofbit | ios_base::failbit));
  1603.  
  1604.   return *this;
  1605. }
  1606. #endif
  1607.  
  1608. /*
  1609.  * istream_type& putback(char_type)
  1610.  */
  1611.  
  1612. template<class charT, class traits>
  1613. basic_istream<charT, traits>&
  1614. basic_istream<charT, traits>::putback(char_type c)
  1615. {
  1616.   ios_base::iostate err = 0;
  1617.  
  1618.   #ifndef _RWSTD_NO_EXCEPTIONS
  1619.   try {
  1620.   #endif 
  1621.   
  1622.   #ifdef _RWSTD_MULTI_THREAD
  1623.    if ( rdbuf() )
  1624.     _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1625.   #endif 
  1626.  
  1627.  if (this->good())
  1628.    {
  1629.      if( traits::eq_int_type(rdbuf()->sputbackc(c),traits::eof()) ) 
  1630.       err = ios_base::badbit;      
  1631.   }
  1632.  else
  1633.   { 
  1634.     if ( !(this->rdstate() & ios_base::failbit) )
  1635.      this->setstate(ios_base::failbit);
  1636.   }
  1637.  
  1638.   #ifndef _RWSTD_NO_EXCEPTIONS
  1639.   }
  1640.   #endif
  1641.  
  1642.   #ifndef _RWSTD_NO_EXCEPTIONS
  1643.   catch(...)
  1644.   {
  1645.     bool flag = false;
  1646.     try {
  1647.           this->setstate(ios_base::badbit);
  1648.         }
  1649.     catch( ios_base::failure ) { flag= true; }
  1650.     if ( flag ) throw;
  1651.   }
  1652.   #endif
  1653.  
  1654.   if ( err ) this->setstate(err);
  1655.  
  1656.   return *this;
  1657. }
  1658.  
  1659. /*
  1660.  * istream_type& unget()
  1661.  */
  1662.  
  1663. template<class charT, class traits>
  1664. basic_istream<charT, traits>&
  1665. basic_istream<charT, traits>::unget()
  1666. {
  1667.   ios_base::iostate err = 0;
  1668.  
  1669.   #ifndef _RWSTD_NO_EXCEPTIONS
  1670.   try {
  1671.   #endif 
  1672.  
  1673.   #ifdef _RWSTD_MULTI_THREAD
  1674.    if ( rdbuf() )
  1675.     _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1676.   #endif
  1677.  
  1678.   if (this->good())
  1679.    {
  1680.      if( traits::eq_int_type(rdbuf()->sungetc(),traits::eof()) )
  1681.       err = ios_base::badbit;  
  1682.    }
  1683.  else
  1684.   { 
  1685.     if ( !(this->rdstate() & ios_base::failbit) )
  1686.      this->setstate(ios_base::failbit);
  1687.   }
  1688.  
  1689.   #ifndef _RWSTD_NO_EXCEPTIONS
  1690.   }
  1691.   #endif
  1692.  
  1693.   #ifndef _RWSTD_NO_EXCEPTIONS
  1694.   catch(...)
  1695.   {
  1696.     bool flag = false;
  1697.     try {
  1698.           this->setstate(ios_base::badbit);
  1699.         }
  1700.     catch( ios_base::failure ) { flag= true; }
  1701.     if ( flag ) throw;
  1702.   }
  1703.   #endif
  1704.  
  1705.   if ( err ) this->setstate(err);
  1706.  
  1707.   return *this;
  1708. }
  1709.  
  1710. /*
  1711.  * streamsize gcount() const
  1712.  */
  1713.  
  1714. template<class charT, class traits>
  1715. streamsize basic_istream<charT, traits>::gcount() const
  1716. {
  1717.   return chcount_;
  1718. }
  1719.  
  1720.  
  1721. /*
  1722.  * int sync()
  1723.  */
  1724.  
  1725. template<class charT, class traits>
  1726. int basic_istream<charT, traits>::sync()
  1727. {
  1728.    ios_base::iostate err = 0;
  1729.  
  1730.    #ifndef _RWSTD_NO_EXCEPTIONS
  1731.    try {
  1732.    #endif 
  1733.   
  1734.   #ifdef _RWSTD_MULTI_THREAD
  1735.    if ( rdbuf() )
  1736.     _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1737.   #endif
  1738.  
  1739.   if(rdbuf()) 
  1740. {  
  1741.  
  1742.     if(rdbuf()->pubsync() == -1)
  1743.       err = ios_base::badbit;  
  1744.     else
  1745.       {
  1746.         if ( this->rdstate() & ios_base::eofbit )
  1747.          clear( this->rdstate() & ~(ios_base::eofbit | ios_base::failbit));
  1748.         return 0;
  1749.       } 
  1750.   }
  1751.  
  1752.   #ifndef _RWSTD_NO_EXCEPTIONS
  1753.   }
  1754.   #endif
  1755.  
  1756.   #ifndef _RWSTD_NO_EXCEPTIONS
  1757.   catch(...)
  1758.   {
  1759.     bool flag = false;
  1760.     try {
  1761.           this->setstate(ios_base::badbit);
  1762.         }
  1763.     catch( ios_base::failure ) { flag= true; }
  1764.     if ( flag ) throw;
  1765.   }
  1766.   #endif
  1767.  
  1768.   if ( err ) this->setstate(err);
  1769.  
  1770.   return -1;
  1771. }
  1772.  
  1773.  
  1774. // string extractor and getline
  1775.  
  1776. #ifndef _RWSTD_NO_NAMESPACE
  1777. }
  1778. namespace __rwstd {
  1779. using namespace std;
  1780. #endif
  1781.  
  1782. template <class streamT, class stringT, class traits>
  1783. streamT& _RWSTDExport rw_extract_string(streamT& is, stringT& s, traits)
  1784. {
  1785.     _TYPENAME streamT::int_type c;
  1786.     ios_base::iostate err = 0;
  1787.  
  1788.  #ifndef _RWSTD_NO_EXCEPTIONS
  1789.  try {
  1790.  #endif  
  1791.  
  1792.     _TYPENAME streamT::sentry ipfx(is);
  1793.  
  1794.     if(ipfx) { 
  1795.  
  1796.       s.erase();
  1797.       c = is.rdbuf()->sbumpc();
  1798.  
  1799.       const ctype<streamT::char_type>& ctype_facet =
  1800. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  1801.         use_facet<ctype<streamT::char_type> >(is.getloc());
  1802. #else
  1803.         use_facet(is.getloc(),(ctype<streamT::char_type>*)0);
  1804. #endif
  1805.  
  1806.       _TYPENAME stringT::size_type i   = 0;
  1807.  
  1808.       _TYPENAME stringT::size_type end = s.max_size();
  1809.       if (is.width())
  1810.         end = (end > (stringT::size_type)is.width()) ? is.width() : end;
  1811.  
  1812.       while ( !traits::eq_int_type(c,traits::eof()) &&  !ctype_facet.is(ctype_facet.space,c) )
  1813.       {
  1814.         s.append(1,traits::to_char_type(c));
  1815.         i++;
  1816.         if ( i == end ) break;
  1817.         c = is.rdbuf()->sbumpc();
  1818.       }
  1819.     if ( i == 0 ) err |= ios_base::failbit;
  1820.     if ( traits::eq_int_type(c,traits::eof()) ) 
  1821.      err |= ios_base::eofbit;
  1822.  
  1823.     }
  1824.  
  1825.   #ifndef _RWSTD_NO_EXCEPTIONS
  1826.   }
  1827.   #endif
  1828.  
  1829.   #ifndef _RWSTD_NO_EXCEPTIONS
  1830.   catch(...)
  1831.   {
  1832.     bool flag = false;
  1833.     try {
  1834.            is.setstate(ios_base::badbit);
  1835.         }
  1836.     catch( ios_base::failure ) { flag= true; }
  1837.     if ( flag ) throw;
  1838.   }
  1839.   #endif
  1840.  
  1841.   if ( err ) is.setstate(err);
  1842.  
  1843.   return is;
  1844. }
  1845.  
  1846.  
  1847. #ifndef _RWSTD_NO_NAMESPACE
  1848. }
  1849. namespace std {
  1850. #endif
  1851.  
  1852. template<class charT, class traits, class Allocator>
  1853. basic_istream<charT,traits>&
  1854. _RWSTDExport getline (basic_istream<charT,traits>& is,
  1855.          basic_string<charT,traits,Allocator>& str,
  1856.          charT delim )
  1857. {
  1858.     _TYPENAME traits::int_type c;
  1859.     ios_base::iostate err = 0;
  1860.  
  1861.  #ifndef _RWSTD_NO_EXCEPTIONS
  1862.  try {
  1863.  #endif  
  1864.  
  1865.     _TYPENAME basic_istream<charT,traits>::sentry ipfx(is,1);
  1866.  
  1867.     if(ipfx) { 
  1868.  
  1869.     str.erase();
  1870.     
  1871.     c = is.rdbuf()->sbumpc();
  1872.     _TYPENAME Allocator::size_type i = 0;
  1873.  
  1874.       while ( !traits::eq_int_type(c,traits::eof()) )
  1875.       {
  1876.         i++;
  1877.         if ( traits::eq(traits::to_char_type(c),delim) )
  1878.             break;
  1879.         if (i == str.max_size())
  1880.         {
  1881.           err |= ios_base::failbit;
  1882.           break;
  1883.         }
  1884.         str.append(1,traits::to_char_type(c));
  1885.         c = is.rdbuf()->sbumpc();
  1886.       }
  1887.  
  1888.      if ( traits::eq_int_type(c,traits::eof()) )
  1889.       err |= ios_base::eofbit;
  1890.  
  1891.     if ( i==0 )
  1892.      err |= ios_base::failbit;
  1893.  
  1894.     }
  1895.  
  1896.  
  1897.   #ifndef _RWSTD_NO_EXCEPTIONS
  1898.   }
  1899.   #endif
  1900.  
  1901.   #ifndef _RWSTD_NO_EXCEPTIONS
  1902.   catch(...)
  1903.   {
  1904.     bool flag = false;
  1905.     try {
  1906.            is.setstate(ios_base::badbit);
  1907.         }
  1908.     catch( ios_base::failure ) { flag= true; }
  1909.     if ( flag ) throw;
  1910.   }
  1911.   #endif
  1912.  
  1913.   if ( err ) is.setstate(err);
  1914.  
  1915.   return is;
  1916. }  
  1917.  
  1918.  
  1919. /*
  1920.  *
  1921.  * class basic_iostream
  1922.  *
  1923.  */
  1924.  
  1925. /*
  1926.  * basic_iostream(basic_streambuf *)
  1927.  */
  1928.  
  1929. template<class charT, class traits>
  1930. basic_iostream<charT, traits>::
  1931. basic_iostream(basic_streambuf<charT, traits> *sb)
  1932. :basic_istream<charT, traits>(sb)
  1933. ,basic_ostream<charT, traits>(sb)
  1934. {
  1935. }
  1936.  
  1937. /*
  1938.  * basic_iostream( )
  1939.  */
  1940.  
  1941. template<class charT, class traits>
  1942. basic_iostream<charT, traits>::
  1943. basic_iostream( )
  1944. {
  1945. }
  1946.  
  1947.  
  1948. /*
  1949.  * ~basic_iostream()
  1950.  */
  1951.  
  1952. template<class charT, class traits>
  1953. basic_iostream<charT, traits>::
  1954. ~basic_iostream()
  1955. {
  1956.  
  1957. }
  1958.  
  1959. #ifndef _RWSTD_NO_NAMESPACE
  1960. }
  1961. #endif
  1962.  
  1963. #pragma option pop
  1964. #endif /* __ISTREAM_CC */
  1965.